home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Project_3 / Calculator.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  60 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import <appkit/Form.h>
  5. #import "Calculator.h"
  6.  
  7. extern double sqrt(double);
  8.  
  9. @implementation Calculator
  10.  
  11. - init
  12. {
  13.    [super init];
  14.    calcType = TEMP;
  15.    return self;
  16.  }
  17.  
  18. - calculate:sender
  19. {
  20.     [inputForm selectTextAt:0];
  21.     if (calcType == TEMP)  {
  22.         float degreesF;
  23.     degreesF = ((9.0 * [inputForm floatValue])/5.0)+32.0;
  24.     [outputForm setFloatValue:degreesF at:0];
  25.     } else if (calcType == SQROOT) {double sqRoot;
  26.     sqRoot= sqrt((double)[inputForm floatValueAt:0]);
  27.     [outputForm setFloatValue:(float)sqRoot at:0];
  28.     }
  29.     return self;
  30. }
  31.  
  32. - convertToTemp:sender
  33. {
  34.      /* label input and output fields */
  35.      calcType = TEMP;
  36.      [inputForm setTitle:"Celsuis:" at:0];
  37.      [outputForm setTitle:"Fahrenheit:" at:0];
  38.      [outputForm setStringValue:"" at:0];
  39.      [inputForm display];
  40.      [outputForm display];
  41.      [inputForm selectTextAt:0];
  42.      return self;
  43.  }
  44.  
  45.  - convertToSqRoot:sender
  46.  {
  47.      /* label input and output fields */
  48.      calcType = SQROOT;
  49.      [inputForm setTitle:"x:" at:0];
  50.      [outputForm setTitle:"sqrt(x):" at:0];
  51.      [outputForm setStringValue:"" at:0];
  52.      [inputForm display];
  53.      [outputForm display];
  54.      [inputForm selectTextAt:0];
  55.      return self;
  56.   }
  57.   
  58.  
  59. @end
  60.